<?php

use App\Interfaces\AdminRouteMenuServiceInterface;
use App\Util\Helper;
use Plugins\AdminBasic\Enums\BasicRouteEnumOpenType;
use Plugins\AdminBasic\Enums\BasicRouteEnumType;
use Plugins\AdminBasic\Http\Admin\Controller\RouteController;
use Sc\Util\HtmlStructure\Form;
use Sc\Util\HtmlStructure\Form\FormItem;
use Sc\Util\HtmlStructure\Html\Html;
use Sc\Util\HtmlStructure\Html\Js\JsFunc;

Html::create('添加路由');
$allRoute = array_map(fn($v) => $v->route, Helper::route()->getRouteList());
$allRoute = array_map(fn($v) => ['value' => $v], array_values($allRoute));

$form = Form::create('routeForm')->config('label-width', '80px');
$menu = Helper::getContainer(AdminRouteMenuServiceInterface::class)->getMenu();

$form->addFormItems(
    FormItem::hidden('id'),
    FormItem::text('title', '标题'),
    FormItem::cascader('pid','上级')->options($menu)
        ->props([
            'value'         => 'index',
            'label'         => 'title',
            'checkStrictly' => true,
            'emitPath'      => false
        ])
        ->closeAfterSelection(),
    FormItem::radio('type', '类型')->options(BasicRouteEnumType::formOptions())->default(BasicRouteEnumType::LeftMenu),
    FormItem::radio('open_type', '打开方式')
        ->options(BasicRouteEnumOpenType::formOptions())
        ->default(BasicRouteEnumOpenType::Default),
    FormItem::text('route', '路由')->options($allRoute),
    FormItem::icon('icon', '图标')->default(''),
    FormItem::submit()->successClose('current')->submitUrl(
        Helper::route()->to([RouteController::class, 'store'])->url(),
        Helper::route()->to([RouteController::class, 'update'])->url(),
    )->success(isset($superConfigAddMenu) ? 'VueApp.super_configGetData()' : 'VueApp.routeGetData()')
);

return $form->render();